package com.takeoutsystem.event.listener;

import com.takeoutsystem.event.message.GetOrderMailEvent;
import com.takeoutsystem.support.MailSenderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class GetOrderMailListener implements ApplicationListener<GetOrderMailEvent> {
    @Override
    public void onApplicationEvent(GetOrderMailEvent getOrderMailEvent) {
        //获取收信人手机号
        String telNumber = getOrderMailEvent.getOrderInfo().getUserTel();
        //获取发送短信内容
        String mailContent=getOrderMailEvent.generateMailContent();
        //发送短信
        boolean result = MailSenderUtil.sendMail(mailContent,telNumber);
        if(result) {
            log.info("{}","成功发送短信");
        }
    }
}
